/**
 * @author hAmmeRoL, created: 2008-7-9
 * SJTU
 */

package protocol.domain;

import java.io.Serializable;


/**
 * Represents a group entry in the buddy list.
 * 
 * @author hAmmeRoL
 * 
 */
public class GroupEntry implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// alias, if no alias, defaults to its id
	private String alias;

	// id of your buddy
	private String id;

	// the group id this entry belongs to.
	// One group only
	// If a buddy belongs to multiple groups, then there
	// will just be multiple entries.
	// 
	// When this id does not belong to any group, it will belong to
	// the unified group
	private String groupName;

	// the presence of this entry
	private UserPresence presence;

	// is blocked
	private boolean isBlocked;

	/**
	 * Construct a new GroupEntry
	 * 
	 * @precondition. none
	 * @postcondition. none
	 * @modifies. none
	 * 
	 * @param alias
	 *            the alias of this entry
	 * @param id
	 *            the id of this entry
	 * @param groupName
	 *            the group name of which this entry belongs to
	 * @param presence
	 *            the presence of this entry
	 */
	public GroupEntry(String alias, String id, String groupName,
			UserPresence presence, boolean isBlocked) {
		this.id = id;
		this.alias = id;
		if (alias != null) {
			this.alias = alias;
		}
		this.groupName = groupName;
		this.presence = presence;
		this.isBlocked = isBlocked;
	}

	public GroupEntry() {

	}

	public String toString() {
		return "Alias: " + alias + ", " + "ID: " + id + ", " + "Group: "
				+ groupName;
	}

	/**
	 * Get alias
	 * 
	 * @precondition. none
	 * @postcondition. none
	 * @modifies. none
	 * 
	 * @return alias
	 */
	public String getAlias() {
		return alias;
	}

	/**
	 * Set alias
	 * 
	 * @precondition. none
	 * @postcondition. alias is changed
	 * @modifies. alias
	 * 
	 * @param alias
	 *            the alias to be set
	 */
	public void setAlias(String alias) {
		this.alias = alias;
	}

	/**
	 * Get group name
	 * 
	 * @precondition. none
	 * @postcondition. none
	 * @modifies. none
	 * 
	 * @return group name
	 */
	public String getGroupName() {
		return groupName;
	}

	/**
	 * Set group name
	 * 
	 * @precondition. none
	 * @postcondition. group name changed
	 * @modifies. group name
	 * 
	 * @param groupName
	 *            the group name to be set
	 */
	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	/**
	 * Get presence
	 * 
	 * @precondition. none
	 * @postcondition. none
	 * @modifies. none
	 * 
	 * @return presence of this entry
	 */
	public UserPresence getPresence() {
		return presence;
	}

	/**
	 * Set presence
	 * 
	 * @precondition. none
	 * @postcondition. presence changed
	 * @modifies. presence
	 * 
	 * @param presence
	 *            the presence to be set
	 */
	public void setPresence(UserPresence presence) {
		this.presence = presence;
	}

	/**
	 * Set the block info
	 * 
	 * @precondition. none
	 * @postcondition. block info is changed
	 * @modifies. the block info
	 * 
	 * @param isBlocked
	 */
	public void setBlocked(boolean isBlocked) {
		this.isBlocked = isBlocked;
	}

	/**
	 * Get the block info
	 * 
	 * @precondition. none
	 * @postcondition. none
	 * @modifies. none
	 * 
	 * @return
	 */
	public boolean isBlocked() {
		return isBlocked;
	}

	/**
	 * Get the id of this entry
	 * 
	 * @precondition. none
	 * @postcondition. none
	 * @modifies. none
	 * 
	 * @return the id of this entry
	 */
	public String getID() {
		return id;
	}

	/**
	 * Two entries are equal if their ids are the same
	 */
	public boolean equals(Object e) {
		if (e instanceof GroupEntry) {
			GroupEntry entry = ((GroupEntry) e);
			if (entry.id.equalsIgnoreCase(id)) {
				return true;
			}
			return false;
		} else {
			return false;
		}
	}

}
